using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using ShivamEMR.Model.Domain.ContactsDomain;
using ShivamEMR.Model.DataInterfaces.ContactsDataInterf;
using ShivamEMR.Model;
//using ShivamEMR.Web.Areas.Contacts.Models;

namespace ShivamEMR.Web.Areas.Contacts.Controllers
{   
    public class NationalityController : Controller
    {
		private readonly INationalityRepository nationalityRepository;

		// If you are using Dependency Injection, you can delete the following constructor
        public NationalityController() 
        {
            nationalityRepository = Registry.RepositoryFactory.GetNationalityRepository();
        }

        public NationalityController(INationalityRepository nationalityRepository)
        {
			this.nationalityRepository = nationalityRepository;
        }

        //
        // GET: /Nationality/

        public ViewResult Index()
        {
            //return View(nationalityRepository.AllIncluding(nationality => nationality.Persons));
            return View(nationalityRepository.All);
        }

        //
        // GET: /Nationality/Details/5

        public ViewResult Details(int id)
        {
            return View(nationalityRepository.Find(id));
        }

        //
        // GET: /Nationality/Create

        public ActionResult Create()
        {
            return View();
        } 

        //
        // POST: /Nationality/Create

        [HttpPost]
        public ActionResult Create(Nationality nationality)
        {
            if (ModelState.IsValid) {
                nationalityRepository.InsertOrUpdate(nationality);
                nationalityRepository.Save();
                return RedirectToAction("Index");
            } else {
				return View();
			}
        }
        
        //
        // GET: /Nationality/Edit/5
 
        public ActionResult Edit(int id)
        {
             return View(nationalityRepository.Find(id));
        }

        //
        // POST: /Nationality/Edit/5

        [HttpPost]
        public ActionResult Edit(Nationality nationality)
        {
            if (ModelState.IsValid) {
                nationalityRepository.InsertOrUpdate(nationality);
                nationalityRepository.Save();
                return RedirectToAction("Index");
            } else {
				return View();
			}
        }

        //
        // GET: /Nationality/Delete/5
 
        public ActionResult Delete(int id)
        {
            return View(nationalityRepository.Find(id));
        }

        //
        // POST: /Nationality/Delete/5

        [HttpPost, ActionName("Delete")]
        public ActionResult DeleteConfirmed(int id)
        {
            var n = nationalityRepository.Find(id);
            nationalityRepository.Delete(n);
            nationalityRepository.Save();

            return RedirectToAction("Index");
        }
    }
}

